package concept.misc;

import java.util.Enumeration;

import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.RollingFileAppender;

public class CustomLogger extends Logger
{
	{
		loadAppenders();
	}
	static final String LOG_HOME = "C:/temp/LOG_TEST";
	static final String APP_NAME = "processor";
	static final String EXTENSION = "log";
	protected CustomLogger(String name)
	{
		super(name);
	}
	private void loadAppenders()
	{
		String profile = System.getProperty("profile", "general");
		Logger rootLogger = Logger.getRootLogger();

		RollingFileAppender fileAppender = null;
		Enumeration<Appender> appenders = rootLogger.getAllAppenders();
		while(appenders.hasMoreElements())
		{
			Appender currentAppender = (Appender)appenders.nextElement();
			if(currentAppender instanceof RollingFileAppender)
			{
				fileAppender = (RollingFileAppender)currentAppender;
				System.err.println("Got it!");
				String level = fileAppender.getThreshold().toString().toLowerCase();
				fileAppender.setFile(LOG_HOME+"/"+profile+"/"+level+"/"+APP_NAME+"_"+level+"."+EXTENSION);
				fileAppender.activateOptions();
			}
		}
	}
}
